import os

MAPBOX_API_KEY = os.getenv('MAPBOX_API_KEY', '')

#CACHE_CONFIG = {
#    'CACHE_TYPE': 'redis',
#    'CACHE_DEFAULT_TIMEOUT': 300,
#    'CACHE_KEY_PREFIX': 'superset_',
#    'CACHE_REDIS_HOST': 'redis',
#    'CACHE_REDIS_PORT': 6379,
#    'CACHE_REDIS_DB': 1,
#    'CACHE_REDIS_URL': 'redis://redis:6379/1'}

# SQLALCHEMY_DATABASE_URI = \
#    'postgresql+psycopg2://superset:superset@postgres:5432/superset'
SQLALCHEMY_DATABASE_URI = \
    'mysql://superset:superset@192.168.179.129:3306/superset'
SQLALCHEMY_TRACK_MODIFICATIONS = True

SECRET_KEY = 'thisISaSECRET_1234'

PUBLIC_ROLE_LIKE_GAMMA = True
BABEL_DEFAULT_LOCALE = "zh"

# https://stackoverflow.com/questions/54010314/using-keycloakopenid-connect-with-apache-superset

# from security import OIDCSecurityManager
# 
# AUTH_TYPE = AUTH_OID
# OIDC_CLIENT_SECRETS = <path_to_configuration_file>
# OIDC_ID_TOKEN_COOKIE_SECURE = False
# OIDC_REQUIRE_VERIFIED_EMAIL = False
# AUTH_USER_REGISTRATION = True
# AUTH_USER_REGISTRATION_ROLE = 'Gamma'
# CUSTOM_SECURITY_MANAGER = OIDCSecurityManager

#ENABLE_PROXY_FIX = True
# source: https://github.com/apache/incubator-superset/pull/1866#issuecomment-347310860
class ReverseProxied(object):

    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
        if script_name:
            environ['SCRIPT_NAME'] = script_name
            path_info = environ['PATH_INFO']
            if path_info.startswith(script_name):
                environ['PATH_INFO'] = path_info[len(script_name):]

        scheme = environ.get('HTTP_X_SCHEME', '')
        if scheme:
            environ['wsgi.url_scheme'] = scheme
        return self.app(environ, start_response)


ADDITIONAL_MIDDLEWARE = [ReverseProxied, ]

